package com.yhyvr.pojo.req.api;

import com.lz.kit.LogKit;
import com.lz.tool.ToolSecurityDES;
import com.lz.tool.des.Des;
import com.yhyvr.pojo.ApiConstant;
import com.yhyvr.pojo.resp.api.ApiRespData;
import com.yhyvr.pojo.resp.api.ApiResultCode;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 客户端请求参数模型
 */
public class ApiReqData<T extends ApiReqBody>{

    /**
     * 请求头部信息（通用参数）
     */
	@Valid
    private ApiReqHead head;
    /**
     * 请求参数
     */
	@Valid
    private T body;

    public ApiReqHead getHead() {
        return head;
    }

    public void setHead(ApiReqHead head) {
        this.head = head;
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }
    public boolean cookieIsLogin(){
        if("weixin".equals(head.getClient())){
            return StringUtils.isNotBlank(head.getUid());
        }

        return head.getUserCookie()!=null;
    }
    public String getCookieUserId(){
        try {
            if(head.getOpenid().equals(ApiConstant.OPENID_WEB_FENXIAO)){
                return  Des.decodeValue(ApiConstant.COOKIE_FENXIAO_USER_DESP0,head.getUserCookie());
            }
        }catch (Exception e){
            LogKit.error(e.getMessage(),e);

        }    return "0000000000000000000000000";
    }
    public String getCrossDomain(){
        return head==null?null:head.getCrossDomain();
    }

    @Override
    public String toString() {
        return "ApiReqData{" +
                "head=" + head +
                ", body=" + body +
                '}';
    }
}
